package com.examination.client.controller;


import com.examination.client.domian.dto.*;
import com.examination.client.domian.vo.CourierSiteTreeDTO;
import com.examination.client.entity.CourierSite;
import com.examination.client.service.ICourierSiteService;
import com.examination.client.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 快递站点信息表 前端控制器
 * </p>
 *
 * @author xiaodong
 * @since 2021-10-17
 */
@RestController
@RequestMapping("/site")
@Api(tags = "站点管理")
@CrossOrigin(origins = "*")
public class CourierSiteController {

    @Resource
    ICourierSiteService courierSiteService;

    @GetMapping("/list")
    @ApiOperation("节点列表")
    public Result<List<CourierSite>> list(CourierSiteQueryDTO courierSiteQueryDTO) {
        return Result.success(courierSiteService.list(courierSiteQueryDTO));
    }

    @GetMapping("/tree/list")
    @ApiOperation("树形节点列表")
    public Result<List<CourierSiteTreeDTO>> treeList(TreeCourierSiteQueryDTO treeCourierSiteQueryDTO) {
        return Result.success(courierSiteService.treeList(treeCourierSiteQueryDTO));
    }

    @GetMapping("/detail")
    @ApiOperation("详情")
    public Result<CourierSite> detail(@RequestParam("id") String id) {
        return Result.success(courierSiteService.getById(id));
    }

    @ApiOperation("添加节点")
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody @Validated CourierSiteDTO courierSiteDTO){
        return Result.success(courierSiteService.save(courierSiteDTO));
    }

    @ApiOperation("删除节点")
    @DeleteMapping("/delete")
    public Result<Boolean> delete(@RequestParam("id") String siteId){
        return Result.success(courierSiteService.removeById(siteId));
    }

    @ApiOperation("修改节点")
    @PutMapping("/modify")
    public Result<Boolean> modify(@RequestBody @Validated CourierSiteDTO courierSiteDTO){
        return Result.success(courierSiteService.modify(courierSiteDTO));
    }

    @ApiOperation("修改节点设置是否主-子账号同时入库")
    @PutMapping("/modify/subsitein")
    public Result<Boolean> modifySubsiteIn(@RequestBody @Validated SubsiteInDTO subsiteInDTO){
        return Result.success(courierSiteService.modifySubsiteIn(subsiteInDTO));
    }
}

